﻿using System.Web;
using System.Web.Mvc;
using EasySite.Services;

namespace EasySite.Web.SessionCaches
{
    public class RolesCache : SessionCacheBase<string[]>
    {
        #region Overrides of SessionCacheBase<string[]>

        protected override string Key
        {
            get { return "RolesCache"; }
        }

        protected override string[] Load()
        {
            if (HttpContext.Current.Request.IsAuthenticated == false)
            {
                return new string[0];
            }
            var service = DependencyResolver.Current.GetService<IUserService>();
            return service.GetRoles(HttpContext.Current.User.Identity.Name);
        }

        #endregion
    }
}